// eslint-disable-next-line no-undef
const { defineConfig } = require("@vue/cli-service");
// eslint-disable-next-line no-undef
const TerserPlugin = require("terser-webpack-plugin");
// eslint-disable-next-line no-undef
const CompressionWebpackPlugin = require("compression-webpack-plugin");
// eslint-disable-next-line no-undef
module.exports = defineConfig({
  publicPath: process.env.NODE_ENV === "production" ? "/designer-service/" : "/",
  transpileDependencies: true,
  devServer: {
    port: 8090,
    client: {
      overlay: false
    },
    headers: {
      "Access-Control-Allow-Origin": "*"
    },
    proxy: {
      "/prod-api": {
        // eslint-disable-next-line no-undef
        target: process.env.VUE_APP_BASE_URL,
        changeOrigin: true,
        pathRewrite: {
          "^/prod-api": ""
        }
      }
    }
  },
  // TODO:封装
  configureWebpack: {
    plugins: [
      // TODO：服务器未配置gz压缩  暂时保留原文件 根据环境是否启用压缩
      // new CompressionWebpackPlugin({
      //   algorithm: "gzip",
      //   test: /\.(js|css)$/,
      //   deleteOriginalAssets: true, // 暂时保留原文件
      //   threshold: 1024,
      //   minRatio: 0.8
      // })
    ],
    optimization: {
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            compress: {
              drop_console: true,
              drop_debugger: true
            }
          }
        })
      ]
    }
  }
});
